define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'csmonline/userlog/index' + location.search,
                    add_url: 'csmonline/userlog/add',
                    edit_url: 'csmonline/userlog/edit',
                    del_url: 'csmonline/userlog/del',
                    multi_url: 'csmonline/userlog/multi',
                    table: 'csmonline_userlog',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'isloginuser', title: __('Isloginuser'), searchList: {"Y":__('Isloginuser y'),"N":__('Isloginuser n')}, formatter: Table.api.formatter.normal},
                        {field: 'userid', title: __('用户唯一标记')},
                        // {field: 'user_id', title: __('用户ID')},
                        {field: 'username', title: __('Username')},
                        {field: 'ip', title: __('Ip')},
                        // {field: 'browserid', title: __('Browserid')},
                        // {field: 'sessionid', title: __('Sessionid')},
                        // {field: 'visitid', title: __('Visitid')},
                        // {field: 'visitdeep', title: __('Visitdeep')},
                        {field: 'url', title: __('Url'), formatter: Table.api.formatter.url},
                        // {field: 'md5url', title: __('Md5url'), formatter: Table.api.formatter.url},
                        // {field: 'useridmd5url', title: __('Useridmd5url'), formatter: Table.api.formatter.url},
                        // {field: 'querystring', title: __('Querystring')},
                        {field: 'title', title: __('Title')},
                        // {field: 'useragent', title: __('Useragent')},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        // {field: 'createdate', title: __('Createdate')},
                        // {field: 'createhour', title: __('Createhour')},
                        // {field: 'createweekday', title: __('Createweekday')},
                        {field: 'durationseconds', title: __('Durationseconds')},
                        // {field: 'durationlasttime', title: __('Durationlasttime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        // {field: 'iscal', title: __('Iscal'), searchList: {"Y":__('Y'),"N":__('N')}, formatter: Table.api.formatter.normal},
                        {field: 'calccountry', title: __('Calccountry')},
                        // {field: 'calcregion', title: __('Calcregion')},
                        {field: 'calcprovince', title: __('Calcprovince')},
                        {field: 'calccity', title: __('Calccity')},
                        // {field: 'calcisp', title: __('Calcisp')},
                        {field: 'calismobile', title: __('设备'), searchList: {"Y":__('手机'),"N":__('PC')}, formatter: Table.api.formatter.normal},
                        {field: 'calplatform', title: __('Calplatform')},
                        {field: 'calbrowser', title: __('Calbrowser')},
                        {field: 'calbrowserversion', title: __('Calbrowserversion')},
                        {field: 'calrobot', title: __('Calrobot')},
                        // {field: 'b1', title: __('B1')},
                        // {field: 'b2', title: __('B2')},
                        // {field: 'b3', title: __('B3')},
                        // {field: 'b4', title: __('B4')},
                        // {field: 'b5', title: __('B5')},
                        // {field: 'b6', title: __('B6')},
                        // {field: 'b7', title: __('B7')},
                        // {field: 'b8', title: __('B8')},
                        // {field: 'b9', title: __('B9')},
                        // {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});